/*
 * Created on 2005-6-1
 *
 * 
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.dcivision.webservice.samples.example4;

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.dcivision.framework.DataSourceFactory;

import com.dcivision.user.bean.UserRecord;
import com.dcivision.webservice.samples.example4.ListUserDAO;
import com.dcivision.webservice.samples.example4.UserException;

public class ListUserBO {
	protected Log log = LogFactory.getLog(this.getClass().getName());
	public ListUserBO(){	  
	}
	public UserRecord[] listAll()
	  throws UserException{	
	Connection con=null;
	UserRecord[] userRecords=null;
	try{
	  con = DataSourceFactory.getConnection();
	  log.debug("ListUserBO begin!");
	  ListUserDAO listUserDAO=new ListUserDAO(con);
	  userRecords=listUserDAO.listAll();
	  log.debug("ListUserBO end!");
	  
	}catch(Exception e){
	  try{
		if(con!=null){
		  con.rollback();
		  throw new UserException(e.getMessage());
		}
	  }catch(SQLException sqle){
		e.printStackTrace();
		throw new RuntimeException("error.unexpected");
	  }
	}finally{
	  try{
		if(con!=null){
		  con.close();
		}
	  }catch(SQLException sqle){
		sqle.printStackTrace();
		throw new RuntimeException("error.unexpected");
	  }
	}
	return userRecords; 
  }
}
